package model

import (
	"XSSS_v2/pkg/auth"
	validator "github.com/go-playground/validator/v10"
)

func GetAdmin(username string) (*Admin, error) {
	admin := Admin{}
	db := DB.Where("aname = ?", username).First(&admin)
	return &admin, db.Error
}

func (admin *Admin) CreateAdmin() error {
	return DB.Create(admin).Error
}

func (admin *Admin) Validate() error {
	validate := validator.New()
	return validate.Struct(admin)
}
func (admin *Admin) Encrypt() (err error) {
	admin.Apwd, err = auth.Encrypt(admin.Apwd)
	return
}
